#!/bin/bash

export FLASK_APP=app.py

# 检查是否已经初始化迁移环境，如果没有则进行初始化
if [ ! -d "migrations" ]; then
    echo "Initializing migration environment..."
    flask db init
fi

# 生成迁移脚本，这里假设每次都是对User模型进行修改，你可以根据实际情况修改描述
echo "Generating migration script..."
flask db migrate -m "Modify User model (example)"

# 应用迁移脚本到数据库
echo "Applying migration script to database..."
flask db upgrade

# 结束后，清除临时文件
echo "Cleaning up..."
rm -rf migrations

# 启动应用程序
echo "Starting the application..."
python app.py --debug=true
